package com.alibaba.yinan.domain.resource.domain;

import com.alibaba.yinan.domain.resource.StorageAreaType;
import lombok.Getter;

/**
 * @author yinan
 * 库位槽
 */
@Getter
public abstract class BaseStorageSlot {

    /**
     * 库位槽编号
     */
    protected final String code;

    /**
     * 库位区域类型
     */
    protected final StorageAreaType areaType;

    /**
     * 当前占用的卡槽
     */
    protected Cassette currentCassette;

    public BaseStorageSlot(String code, StorageAreaType areaType) {
        this.code = code;
        this.areaType = areaType;
    }

    public boolean isAvailable(Cassette cassette) {
        return currentCassette == null && support(cassette);
    }

    protected abstract boolean support(Cassette cassette);

    public void assignCassette(Cassette cassette) {
        if (!isAvailable(cassette)) {
            throw new IllegalStateException("库位不可用或类型不匹配：" + code);
        }
        this.currentCassette = cassette;
    }

    public void releaseCassette() {
        this.currentCassette = null;
    }
}
